/**
 * 
 */
package Parser;

import java.util.ArrayList;

import LexicalAnalyzer.Token;

/**
 * @author akanter
 *
 */
public class NonTerminal extends Symbol {

	public NonTerminal(String str){
		children = new ArrayList<Symbol>();
		this.content=str;
	}
	
	
	/* (non-Javadoc)
	 * @see Parser.Symbol#matches(LexicalAnalyzer.Token)
	 */
	@Override
	public boolean matches(Token t) {
		//NonTerminals should always return false!
		return false;
	}

	/* (non-Javadoc)
	 * @see Parser.Symbol#isTerminal()
	 */
	@Override
	public boolean isTerminal() {
		return false;
	}

	public String toString(){
		return this.toString(0);
	}
	
	/**
	 * Recursive helper method for toString (protected)
	 */
	protected String toString(int depth){
		StringBuilder sb = new StringBuilder();
		sb.append("(" +content +'\n');
		StringBuffer sb2 = new StringBuffer();
		for(int i=0;i<depth;i++){
			sb2.append("   ");
		}
		for(Symbol elt : children){    //Sets up # of tabs required to show tree for the children of this node
			sb.append(sb2 + "   ");
			if (elt.isTerminal()){
				sb.append(elt.toString()+ '\n');
			}
			else sb.append(elt.toString(depth+1) + '\n');
		}
		sb.append(sb2 + " )");
		return sb.toString();
	}
	
}
